package org.csu.jpetstore_cms.service.impl;

import org.csu.jpetstore_cms.mapper.CategoryMapper;
import org.csu.jpetstore_cms.mapper.ItemMapper;
import org.csu.jpetstore_cms.mapper.ProductMapper;
import org.csu.jpetstore_cms.pojo.Account;
import org.csu.jpetstore_cms.pojo.Category;
import org.csu.jpetstore_cms.pojo.Item;
import org.csu.jpetstore_cms.pojo.Product;
import org.csu.jpetstore_cms.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceimpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private ItemMapper itemMapper;
    @Autowired
    private ProductMapper productMapper;
    @Override
    public List<Category> getall() {
        return categoryMapper.getall();
    }

    @Override
    public  List<Item> getItem(String itemid) {
        return itemMapper.getItem(itemid);
    }

    @Override
    public List<Item> getAllItem() {
        return itemMapper.getAllItem();
    }

    @Override
    public List<Product> getAllProduct() {
        return productMapper.getAllProduct();
    }

    @Override
    public List<Item> getItemByProductId(String productId) {
        return itemMapper.getItemByProductId(productId);
    }

    @Override
    public void DeleteByItemId(String itemid) {
        itemMapper.DeleteByItemid(itemid);
    }

    @Override
    public void DeleteByProductId(String productid) {
        productMapper.DeleteItemByProductId(productid);
        productMapper.DeleteByProductId(productid);
    }

    @Override
    public void CreatCategory(Category category) {
        categoryMapper.CreatCategory(category);
    }

    @Override
    public void DeleteByCategoryId(String categoryid) {
        categoryMapper.deleteItemsByCategory(categoryid);
        categoryMapper.deleteProductsByCategory(categoryid);
        categoryMapper.deleteCategoryById(categoryid);
    }

    @Override
    public void CreatProduct(Product product) {
        productMapper.CreatProduct(product);
    }

    @Override
    public void CreatItem(Item item) {
        itemMapper.CreatItem(item);
    }

    @Override
    public void UpdateItem(Item item) {
        itemMapper.UpdateItem(item);
    }

    @Override
    public List<Product> getProductByCategoryId(String categoryid) {
        List<Product> productList = productMapper.getProductByCategoryId(categoryid);
        return productList;
    }

    @Override
    public void UpdateProduct(Product product) {
        productMapper.UpdateProduct(product);
    }

    @Override
    public void UpdateCategory(Category category) {
        categoryMapper.UpdateCategory(category);
    }

//    @Override
//    public Account Login(Account account) {
//        Account account1 =  categoryMapper.login(account);
//        return account1;
//    }
     public List<Item> findByPage(Integer pageNum, Integer pageSize) {
        return itemMapper.findByPage(pageNum,pageSize);
     }
    public int getTotalCount(){
        return itemMapper.getCount();
    }
}
